package com.controller.after;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.controller.base.BaseController;
import com.entity.UserIndustry;
import com.service.IndustryService;

@Controller
@RequestMapping("/Industry/")
//用户行业
public class UserIndustryController extends BaseController<Object>{
	//用户行业
	@Autowired
	private IndustryService IndService;
	
	@RequestMapping("/findByPage")
	@ResponseBody
	public AjaxRes findByPage(UserIndustry o,Page<UserIndustry> page)throws Exception{
		AjaxRes res=new AjaxRes();
		Page<UserIndustry> indPages =IndService.findByPage(o, page);
		res.setSucceed(indPages, "数据获取成功");
		return res;
	}
	
	@RequestMapping("/ShowUpdate")
	@ResponseBody
	public ModelAndView ShowUpdate(String id)throws Exception{

		ModelAndView mv =  new ModelAndView();
		if(id!="" && id!=null){
			UserIndustry o=new UserIndustry();
			o.setUserIndustryId(id);
			List<UserIndustry> list=IndService.find(o);
			mv.addObject("indu", list.get(0));
		}
		mv.setViewName("pages/Industry/UpdateIndustry");
		return mv;
	}
	
	@RequestMapping("/Update")
	@ResponseBody
	public AjaxRes Update(UserIndustry Industry)throws Exception{
	
		AjaxRes res=new AjaxRes();
		IndService.update(Industry);
		res.setResMsg("添加成功");
		return res;
	}
	
	
	@RequestMapping("/ShowAdd")
	@ResponseBody
	public ModelAndView ShowAdd()throws Exception{
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/Industry/addIndustry");
		return mv;
	}
	
//	@RequestMapping("/Add")
//	@ResponseBody
//	public AjaxRes Add(UserIndustry Industry)throws Exception{
//		AjaxRes res=new AjaxRes();
//		IndService.insert(Industry);
//		res.setResMsg("添加成功");
//		return res;
//	}
	
	@RequestMapping("/Delel")
	@ResponseBody
	public ModelAndView Delel(String id)throws Exception{
		ModelAndView mv =  new ModelAndView();
		UserIndustry o=new UserIndustry();
		o.setUserIndustryId(id);
		IndService.delete(o);
		mv.setViewName("pages/Industry/IndustryContent");
		return mv;
	}
	
	@RequestMapping("/DelelList")
	@ResponseBody
	public ModelAndView DelelList(String idList)throws Exception{
		ModelAndView mv =  new ModelAndView();
		List<String>  gameids= java.util.Arrays.asList(idList.split(","));
		List<UserIndustry> IndList=new ArrayList<UserIndustry>();
		for(int i=0;i<gameids.size();i++){
			UserIndustry o=new UserIndustry();
			o.setUserIndustryId(gameids.get(i));
			IndList.add(o);
		}
		IndService.deleteBatch(IndList);
		mv.setViewName("pages/Industry/IndustryContent");
		return mv;
	}
}
